<?php
// card id  pe2K2jueSlpaafyz1PB30pXpeInk
ini_set('display_errors', 'On');

define('APPID', 'wxe214ac48790c622f');
define('SECRET', '62d3091e10b72a50a8a2c4f758a799b2');//selim
$access_token = get_access_token();

function getcard($access_token) {
    
    $url = "https://api.weixin.qq.com/card/get?access_token=".$access_token;
    $data = '{"card_id":"pE4KPweE9pIGFZLNYyiGcQsg4LcY"}';
    $res = https_request( $url ,'post', 'json', $data);
 
    echo print_r($res['card']);
}
//getcard($access_token);

$url='https://api.weixin.qq.com/card/update?access_token='.$access_token;
$logo_url='http://mmbiz.qpic.cn/mmbiz_jpg/VDBKliauDV44ibw7xsZVFzoCFuI5qRUhOZBl8IjT6EvO2255ALk60x2U2XQlLwdupDX0LeQxnDTLHA0m5nrThicZA/0?wx_fmt=jpeg';
$data = '{"card_id":"pE4KPweE9pIGFZLNYyiGcQsg4LcY",
       "general_coupon": {
               "base_info": {
                   "color": "Color010",
                   "description": ""}}}';

$res = https_request( $url ,'post', 'json', $data);
var_dump($res);
echo 'done';














function get_access_token(){
    $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".SECRET;
 
    $res = https_request($url, 'get', 'json');
    
    $access_token = $res["access_token"];
    return $access_token;
}
function https_request($url, $type="get", $res="json", $data = ''){
    //1.初始化curl
    $curl = curl_init();
    //2.设置curl的参数
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    if ($type == "post"){
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    }
    //3.采集
    $output = curl_exec($curl);
    //var_dump(curl_getinfo($curl));
    //4.关闭
    curl_close($curl);
    if ($res == 'json') {
        return json_decode($output,true);
    }
}
